package com.wbw.csnd_hd.configs;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2 //开启swagger2
@Configuration
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    //自定义swagger的配置（不配置的化，下面的代码都可以不写）
    @Bean
    public Docket docket(Environment enviro ){
        //.enable(flag)设置swagger不启动,一般用于多套环境中，切换至上线环境就禁用swagger
        //设置要显示swagger的环境
//        Profiles of = Profiles.of("dev", "test");//环境名dev，test
//        //通过Environment来判断当前环境是否是要显示swagger的环境
//        boolean flag = enviro.acceptsProfiles(of);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apio())
//                .enable(flag)设置swagger不启动flag==false时，就不会启动swagger
                //下面三个，是指定扫描某个包下的方法
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wbw.csnd_hd.controller"))
                .build();
    }

    //把配置的swagger信息放在这里面
    private ApiInfo apio()  {
        //作者信息
        Contact contact = new Contact("王博文", "null", "1265002192@qq.com");
        return new ApiInfo(
                "王博文的接口文档",
                "wbw",
                "v1.0",
                "null",
                contact,
                "Apache 2.0",
                "null",
                new ArrayList<>()
        );
    }





}
